package com.zee.example.angle

import android.os.Bundle
import com.google.gson.Gson

import com.zee.example.R

import com.zee.http.MyOk
import com.zee.log.ZLog
import kotlinx.android.synthetic.main.activity_rj.*
import org.json.JSONObject
import java.util.HashMap
import com.google.gson.reflect.TypeToken
import com.zee.base.ZActivity
import com.zee.example.RJAPPBean
import com.zee.http.request.ZCacheStringResult
import com.zee.http.request.ZStringResult
import com.zee.http.utils.HttpLoggingInterceptor
import com.zee.recyclerview.RefreshAndLoadMordAdapter
import com.zee.utils.UIUtils


class RJActivity : ZActivity() {
    val list = ArrayList<RJAPPBean.DataBean.AppListBean>();
    var page = 1;

    override fun getLayoutResID(): Int {
        return R.layout.activity_rj
    }

    override fun initViews(savedInstanceState: Bundle?) {
//        moreAppListAdapter = MoreAppListAdapter(list)
//        moreAppListAdapter.setItemClickListener { bean, position ->
//            UIUtils.showToastShort("${bean}" + position)
//        }
//        moreAppListAdapter.setOnItemViewClickListener { bean, view, position ->
//            UIUtils.showToastShort("看好了，不是：${bean}" + position)
//        }
//
//        recyclerview_RJ.adapter = moreAppListAdapter
//
//        loadData(page)
//        recyclerview_RJ.setRefreshAndLoadMordListener(object : RefreshAndLoadMordAdapter() {
//            override fun onStartLoad(curPage: Int) {
//                loadData(page)
//            }
//        })
    }

    fun loadData(paCurpage: Int) {
        ZLog.i("当前页数:" + paCurpage)
        val loStringObjectHashMap = HashMap<String, Any>()
        loStringObjectHashMap["catId"] = "other"
        loStringObjectHashMap["menuId"] = "system_security"
        loStringObjectHashMap["pageSize"] = "2"
        loStringObjectHashMap["pageIndex"] = paCurpage



//        MyOk.load("https://api.wn.work/appstore-web-api/getGroupAppList").postJson(loStringObjectHashMap).addInterceptor(ThirdPartyInterceptor()).execute(object : ZCacheStringResult() {
//            override fun onSuccessAsyncThread(data: String?, isFromCache: Boolean) {
//
//               val bean: RJAPPBean.DataBean = optObject("data", RJAPPBean.DataBean::class.java,true)
//
//               ZLog.i("数据:" + data)
//               val dataA = JSONObject(data);
//               val dataB = dataA.getJSONObject("data");
//               val totalPage = dataB.getInt("totalPage")
//
//               val loList = Gson().fromJson(dataB.getString("appList"), object : TypeToken<List<AppListBean>>() {
//               }.type) as List<AppListBean>
//               list.addAll(loList)
//               moreAppListAdapter.notifyDataSetChanged()
//               ZLog.e("显示页数${paCurpage}/$totalPage");
//               UIUtils.runOnMainThread {
//                   recyclerview_RJ.setLoadMoreEnabled((paCurpage < totalPage))
//               }
//            }
//
//            override fun onError(isCache: Boolean, e: Exception) {
//                ZLog.i(isCache.toString() + "进入onError()->" + Thread.currentThread().name)
//            }
//
//            override fun onEnd() {
//                recyclerview_RJ.loadFinish()
//                ZLog.i("进入onEnd()->" + Thread.currentThread().name)
//            }
//        })

    }
}
